import {
  getUserInfoAPI,
  getUserProfileAPI,
  updatePhotoAPI,
  updateProfileAPI,
} from '@/api/user';
import { AppDispatch } from '..';
import { IUserProfile } from '@/store/reducer/user';

export const getUserInfoAction = () => {
  return async (dispatch: AppDispatch) => {
    const res = await getUserInfoAPI();
    dispatch({ type: 'user/saveInfo', payload: res.data });
  };
};

export const getUserProfileAction = () => {
  return async (dispatch: AppDispatch) => {
    const res = await getUserProfileAPI();
    dispatch({ type: 'user/saveProfile', payload: res.data });
  };
};

export const updatePhotoAction = (formData: FormData) => {
  return async () => {
    const res = await updatePhotoAPI(formData);
    console.log('res  ----->  ', res);
  };
};

// 2.
export const updateProfileAction = (data: Partial<IUserProfile>) => {
  return async () => {
    const res = await updateProfileAPI(data);
    console.log('res  ----->  ', res);
  };
};
